const TronWeb = require('tronweb')
// C = TronWeb.createAccount()
/*
Promise {
    {
      privateKey: 'CF1CD5586390FEA4B1537BD24061B0A89412C4DCD3FE4DC83E3EE11FA78AE4FD',
      publicKey: '049D03FE469B342D0AB3A88AA55F9C661A50026BB2AC718CB4209A792E3D8B52B15AA2DB6448F19F3D1EDF5F87946B65B1468A53EC7F3EBEB8F0720BA63165B8A4',
      address: {
        base58: 'TTPMFTd3QRTU9WgyxkeButVqorzECn8rr2',
        hex: '41BF0B01B93C5E181DA973E32E3617FDCD2FC3C8F4'
      }
    }
  }
  */
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider("https://api.trongrid.io");
const solidityNode = new HttpProvider("https://api.trongrid.io");
const eventServer = new HttpProvider("https://api.trongrid.io");
const privateKey = "CF1CD5586390FEA4B1537BD24061B0A89412C4DCD3FE4DC83E3EE11FA78AE4FD";
const tronWeb = new TronWeb(fullNode,solidityNode,eventServer,privateKey);
tronWeb.setHeader({"TRON-PRO-API-KEY": 'f3c1c389-b115-438e-bdd9-02b2e9db8798'});



/**
 * 获取指定地址的trx数量
 * @param address
 * @returns {Promise<number>}
 */
balanceOf = async function (address) {
    let balance = await tronWeb.trx.getBalance(address);
    return Number(tronWeb.fromSun(balance).toString());
};
console.log(tronWeb.isConnected())
console.log(tronWeb.trx.getBalance('TTPMFTd3QRTU9WgyxkeButVqorzECn8rr2'))